package rpc

import (
	"fmt"
	"net/rpc"
	"net/rpc/jsonrpc"
	"strconv"
)

func HttpClient() {
	client, err := rpc.DialHTTP("tcp", "localhost:1234")
	checkError(err)

	args := Args{A: 7, B: 8}
	var reply int
	client.Call("CalcService.Sum", &args, &reply)
	fmt.Println("reply=" + strconv.Itoa(reply))

	r := Result{}
	client.Call("CalcService.Calc", &args, &r)
	fmt.Println(r)

	client.Call("HelloService.Hello", &Empty{}, &Empty{})
}

func TcpClient() {
	client, err := rpc.Dial("tcp", "localhost:1234")
	checkError(err)

	args := Args{A: 12, B: 23}
	var r int
	client.Call("CalcService.Sum", &args, &r)
	fmt.Println("result=" + strconv.Itoa(r))

	result := Result{}
	client.Call("CalcService.Calc", &args, &result)
	fmt.Println(result)

	client.Call("HelloService.Hello", &Empty{}, &Empty{})
}

func JsonRpcClient() {
	client, err := jsonrpc.Dial("tcp", "localhost:1234")
	checkError(err)

	args := Args{A: 12, B: 100}
	var r int
	client.Call("CalcService.Sum", &args, &r)
	fmt.Println(r)

	result := Result{}
	client.Call("CalcService.Calc", &args, &result)
	fmt.Println(result)

	client.Call("HelloService.Hello", &Empty{}, &Empty{})
}
